package miracle.joker.design.memento;

public class MementoDemo {
    public static void main(String[] args) {
        // 创建文本编辑器对象
        TextEditor editor = new TextEditor("Hello, world!");

        // 创建CareTaker对象
        Caretaker caretaker = new Caretaker();

        // 添加Memento对象到Caretaker
        caretaker.addMemento(editor.getMemento());

        // 修改文本内容并保存
        editor.setText("Hello, Java!");
        caretaker.addMemento(editor.getMemento());

        // 再次修改文本内容并保存
        editor.setText("Hello, Design Patterns!");
        caretaker.addMemento(editor.getMemento());
        // 撤销操作
        editor.undo();
        System.out.println(editor.getText());

        // 撤销操作
        editor.undo();
        System.out.println(editor.getText());

        // 重做操作
        editor.redo();
        System.out.println(editor.getText());
    }
}
